package com.ly.web.controller.erp;

import com.ly.common.annotation.Log;
import com.ly.common.core.controller.BaseController;
import com.ly.common.core.domain.AjaxResult;
import com.ly.common.enums.BusinessType;
import com.ly.common.utils.StringUtils;
import com.ly.heart.domain.CustomerVisitEntity;
import com.ly.heart.domain.dto.CustomerVisitDto;
import com.ly.heart.service.ICustomerVisitService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 客户拜访申请 前端控制器
 * </p>
 * @author WuZH
 * @since 2024-09-29
 */
@Api (value = "CustomerVisit", tags = "客户拜访申请")
@RestController
@RequestMapping ("/heart/CustomerVisit")
public class CustomerVisitController extends BaseController {

    @Resource
    private ICustomerVisitService iCustomerVisitService;

    @PreAuthorize ("@ss.hasPermi('heart/CustomerVisit:list')")
    @GetMapping ("/list")
    @ApiOperation ("查询客户拜访申请单列表")
    public AjaxResult list (CustomerVisitEntity customerVisitEntity) {
        return iCustomerVisitService.list ( customerVisitEntity );
    }

    @PreAuthorize ("@ss.hasPermi('heart:CustomerVisit:query')")
    @GetMapping (value = "/{id}")
    @ApiOperation ("查询客户拜访申请单详情")
    public AjaxResult getInfo (@PathVariable ("id") String id) {
        return AjaxResult.success ( iCustomerVisitService.querySingle ( id ) );
    }

    @PreAuthorize ("@ss.hasPermi('heart:CustomerVisit:add')")
    @Log (title = "新增客户拜访申请单", businessType = BusinessType.INSERT)
    @PostMapping("draft")
    @ApiOperation ("新增客户拜访申请单")
    public AjaxResult draft (@RequestBody CustomerVisitDto customerVisitDto) {
        if ( StringUtils.isNotBlank ( customerVisitDto.getCustomerVisitEntity ().getId () ) ) {
            return iCustomerVisitService.updateSingle ( customerVisitDto );
        }
        return iCustomerVisitService.draft ( customerVisitDto );
    }

    @PreAuthorize ("@ss.hasPermi('heart:CustomerVisit:add')")
    @Log (title = "新增客户拜访申请单", businessType = BusinessType.INSERT)
    @PostMapping("submit")
    @ApiOperation ("新增客户拜访申请单")
    public AjaxResult submit (@RequestBody CustomerVisitEntity customerVisitEntity) {
        return iCustomerVisitService.submit ( customerVisitEntity );
    }

    @PreAuthorize ("@ss.hasPermi('heart:CustomerVisit:edit')")
    @Log (title = "修改客户拜访申请单", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation ("修改客户拜访申请单")
    public AjaxResult edit (@RequestBody CustomerVisitDto customerVisitDto) {
        return iCustomerVisitService.updateSingle ( customerVisitDto );
    }

    @PreAuthorize ("@ss.hasPermi('heart:CustomerVisit:remove')")
    @Log (title = "删除客户拜访申请单", businessType = BusinessType.DELETE)
    @DeleteMapping ("/{ids}")
    @ApiOperation ("删除客户拜访申请单")
    public AjaxResult remove (@PathVariable String id) {
        return iCustomerVisitService.deleteSingle ( id );
    }
}
